LogGrad ================= 计算对数函数(Log)的梯度。 该算子用于反向传播阶段,依据链式法则, 将上游梯度与 Log 输入张量进行逐元素相除, 其数学表达式如下: .. math:: \text{output}_i = \frac{\text{input0}_i}{\text{input1}_i} 其中: - ``input0`` 表示上游梯度(dY) - ``input1`` 表示 Log 算子的输入(X) 输入: - **input0** - 上游梯度张量的数据地址。 - **input1** - Log 算子前向输入张量的数据地址。 - **length** - 输入张量的总元素数量。 - **core_mask** - 核掩码。 输出: - **output** - 输出梯度张量的数据地址。 支持平台: ``FT78NE`` ``MT7004`` .. note:: - FT78NE 支持的数据类型:fp32 - MT7004 支持的数据类型:fp16, fp32 - 当 ``input1`` 中存在 0 或极小值时,结果可能产生 ``±∞`` 或 ``NaN``,需由上层框架保证输入合法性 **共享存储版本:** .. c:function:: void fp_log_grad_s(float* input0, float* input1, float* output, int length, int core_mask) .. c:function:: void hp_log_grad_s(half* input0, half* input1, half* output, int length, int core_mask) **C调用示例:** .. code-block:: c :linenos: :emphasize-lines: 13 // FT78NE 多核示例 #include #include int main(int argc, char* argv[]) { float *input0 = (float *)0xA0000000; // 上游梯度 float *input1 = (float *)0xA0100000; // Log 前向输入 float *output = (float *)0xB0000000; // 输出梯度 int length = 4096; int core_mask = 0xff; fp_log_grad_s(input0, input1, output, length, core_mask); return 0; } **私有存储版本:** .. c:function:: void fp_log_grad_p(float* input0, float* input1, float* output, int length) .. c:function:: void hp_log_grad_p(half* input0, half* input1, half* output, int length) **C调用示例:** .. code-block:: c :linenos: :emphasize-lines: 12 // MT7004 单核示例 #include #include int main(int argc, char* argv[]) { half *input0 = (half *)0x10000000; half *input1 = (half *)0x10010000; half *output = (half *)0x10020000; int length = 1024; hp_log_grad_p(input0, input1, output, length); return 0; }